package com.ganzalang.gmall.learning.netty.nio.zerocopy;

import lombok.extern.slf4j.Slf4j;

import java.io.DataInputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @description: 传统IO服务端
 * @author: Ganzalang
 * @Date 2021/7/15 14:49
 */
@Slf4j
public class OldIOServer {

    public static void main(String[] args) throws Exception{
        ServerSocket serverSocket = new ServerSocket(7001);

        while (true) {
            Socket socket = serverSocket.accept();
            DataInputStream dataInputStream = new DataInputStream(socket.getInputStream());

            log.info("开始拷贝数据");
            try {
                byte[] byteArray = new byte[4096];
                int readCount = dataInputStream.read(byteArray, 0, byteArray.length);

                if (readCount == -1) {
                    break;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
